package cn1shared.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class IoUtils {

	private IoUtils() {}  // never

	private static final int bufSize = 8192;

	public static void copyAll(InputStream in, OutputStream out) throws IOException {
		byte[] a = new byte[bufSize];
		int n;
		while ((n=in.read(a)) != -1) {
			out.write(a,0,n);
		}
	}

	public static byte[] readAll(InputStream in)
		throws IOException
	{
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		copyAll(in, out);
		return out.toByteArray();
	}

}
